package com.shirley.algorithm.sort;

import java.util.Arrays;

public class ShellSort extends SortBase {
    public static int[] sort(int[] sourceArr) {
        int[] arr = Arrays.copyOf(sourceArr, sourceArr.length);

        for (int step = arr.length / 2; step > 0; step /= 2) {
            // 插入排序
            for (int i = step; i < arr.length; i++) {
                int j = i;
                while (j >= step && arr[j] < arr[j - step]) {
                    swap(arr, j, j - step);
                    j--;
                }
            }
        }
        return arr;
    }

}
